const AipOcrClient = require('baidu-aip-sdk').ocr
const HttpClient = require('baidu-aip-sdk').HttpClient
console.log('AipOcrClient:', AipOcrClient)
const fs = require('fs')

const appConfig = {
	appId: '24757210',
	appKey: 'xK8O6Xy0aH3Z3LFOfeEvldEK',
	secretKey: 'MS5PB2abonaetWvGLrArgIoFQ46FmNAK'
}

class OcrManage {
	constructor(app) {
		this.config = appConfig
		this.aipClient = new AipOcrClient(
			this.config.appId,
			this.config.appKey,
			this.config.secretKey
		)
	}

	// async返回一个promise
	async accurateBasic(imageBase) {
		let result = await this.aipClient.accurateBasic(imageBase)
		return result
	}
}

module.exports = {
	ocrManage: new OcrManage()
}

// const fileImage = fs.readFileSync('./1.png')
// // console.log('fileImage:', fileImage.toString('base64'))

// const ocrinstance = new OcrManage()

// ocrinstance.accurateBasic(fileImage.toString('base64')).then((res) => {
// 	console.log('res:', res)
// })

// module.exports = function (app) {
// 	let libs = {
// 		ocrManage: new OcrManage(app)
// 	}
// 	return { libs }
// }
